//
//  NXMRootViewController.swift
//  AnneKit-Swift
//
//  Created by 宁小陌 on 2021/2/3.
//  Copyright © 2021 宁小陌. All rights reserved.
//

import UIKit

class NXMRootViewController: UITabBarController {
    override func viewDidLoad() {
        super.viewDidLoad()
        //禁止tabBar透明
        tabBar.isTranslucent = false
        setupTabBarItemTextColor()
        //首页
        
        //分类
       
        addChildVC(childVC: NXMHomeViewController(), title: "首页", norimage: "tab_home_nor", selectedImg: "tab_home_press")
        addChildVC(childVC: NXMServerViewController(), title: "商家", norimage: "tab_business_nor", selectedImg: "tab_business_press")
        addChildVC(childVC: NXMCommuMainViewController(), title: "工具", norimage: "tab_tool_nor", selectedImg: "tab_tool_press")
        addChildVC(childVC: NXMMineViewController(), title: "我的", norimage: "tab_mine_nor", selectedImg: "tab_mine_press")
    }
    
    func setupTabBarItemTextColor() {
        //设置为点击文字颜色
        UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.foregroundColor : UIColor.kTabBarColorNormal], for: UIControl.State.normal)
        //设置点击之后文字颜色
        UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.foregroundColor : UIColor.kTabBarColorSelected], for: UIControl.State.selected)
    }

    func addChildVC(childVC: UIViewController, title: String, norimage: String,selectedImg:String) {

        tabBarItem.setTitleTextAttributes([NSAttributedString.Key.foregroundColor : UIColor.red], for: .highlighted)
        var img = UIImage(named: norimage)
        img = img?.withRenderingMode(UIImage.RenderingMode.alwaysOriginal)

        var selectedImg = UIImage(named:selectedImg)
        selectedImg = selectedImg?.withRenderingMode(UIImage.RenderingMode.alwaysOriginal)

        childVC.tabBarItem.image = img
        childVC.tabBarItem.selectedImage = selectedImg
        childVC.title = title

        let nav = UINavigationController(rootViewController: childVC)
        addChild(nav)
    }
    
    
//    func addChildVc(childName: String,title: String,normalImageNamed: String,selectedImageName: String) {
//        // 1.设置子控制器的默认设置
//        Class Controller = NSClassFromString(childName);
//    }
}
